//
//  MJ_OrderContentLayout.m
//  UEAssistant
//
//  Created by mac on 2018/1/3.
//  Copyright © 2018年 youyixinxi. All rights reserved.
//

#import "MJ_OrderContentLayout.h"
#import "UIColor+Extend.h"
@implementation MJ_OrderContentLayout

- (id)copyWithZone:(NSZone *)zone {
    
    MJ_OrderContentLayout *layout = [[MJ_OrderContentLayout alloc] init];
    layout.cellHeight = self.cellHeight;
    return layout;
}

- (instancetype)initWithModel:(MJ_TaskListResult *)model index:(NSInteger)index type:(MJTaskOrder)type
{
    self = [super init];
    if (self) {

        if (index == 0) {
            LWTextStorage *projectTitle = [[LWTextStorage alloc] init];
            projectTitle.text = @"所属项目";
            projectTitle.frame = CGRectMake(18, 18, Screen_Width, 13);
            projectTitle.textColor = [UIColor colorWithHexString:@"#999999"];
            projectTitle.font = [UIFont systemFontOfSize:13];
            [self addStorage:projectTitle];
            
            LWTextStorage *projectContent = [[LWTextStorage alloc] init];
            if (model.projectName == nil) {
                projectContent.text = model.project_name;
            }else{
                projectContent.text = model.projectName;
            }
            projectContent.frame = CGRectMake(18, projectTitle.bottom+9.0, Screen_Width-36, CGFLOAT_MAX);
            projectContent.textColor = [UIColor colorWithHexString:@"#333333"];
            projectContent.font = [UIFont systemFontOfSize:14];
            [self addStorage:projectContent];
            
        }else if (index == 1) {
            //蓝色的竖线
            LWImageStorage *tagImage = [[LWImageStorage alloc] init];
            tagImage.frame = CGRectMake(18, 18, 2.5, 12);
            tagImage.backgroundColor = [UIColor colorWithHexString:@"#0084ff"];
            [self addStorage:tagImage];
            
            LWTextStorage *deadTimeTitle = [[LWTextStorage alloc] init];
            deadTimeTitle.text = @"截止时间";
            deadTimeTitle.frame = CGRectMake(tagImage.right + 9.0, 18, Screen_Width, 13);
            deadTimeTitle.textColor = [UIColor colorWithHexString:@"#999999"];
            deadTimeTitle.font = [UIFont systemFontOfSize:13];
            [self addStorage:deadTimeTitle];
            
            LWTextStorage *deadTimeContent = [[LWTextStorage alloc] init];
            if (model.deadline_time == nil) {
                deadTimeContent.text = model.deadLineTime;
            }else{
                deadTimeContent.text = model.deadline_time;
            }
            deadTimeContent.frame = CGRectMake(deadTimeTitle.left, deadTimeTitle.bottom+9.0, Screen_Width, 20);
            deadTimeContent.textColor = [UIColor colorWithHexString:@"#333333"];
            deadTimeContent.font = [UIFont systemFontOfSize:14];
            [self addStorage:deadTimeContent];
        }else if (index == 2) {
            
            LWTextStorage *taskContentTitle = [[LWTextStorage alloc] init];
            taskContentTitle.text = model.taskName;
            taskContentTitle.frame = CGRectMake(18, 18, Screen_Width, 20);
            taskContentTitle.textColor = [UIColor colorWithHexString:@"#333333"];
            taskContentTitle.font = [UIFont systemFontOfSize:14];
            [self addStorage:taskContentTitle];
            
            NSArray *titleArray = @[@"语种",@"字数",@"任务类型",@"任务标签"];
            if (CurrentUserType == 4 || CurrentUserType == 5) {
                titleArray = @[@"语种",@"字数",@"价格",@"任务类型",@"任务标签"];
            }
            NSMutableArray *titleStorages = [NSMutableArray array];
            for (NSInteger i = 0; i < titleArray.count; ++ i) {
                LWTextStorage *title = [[LWTextStorage alloc] init];
                title.text = titleArray[i];
                title.frame = CGRectMake(18, taskContentTitle.bottom+9.0+i*24, Screen_Width, CGFLOAT_MAX);
                title.textColor = [UIColor colorWithHexString:@"#666666"];
                title.font = [UIFont systemFontOfSize:13];
                [self addStorage:title];
                [titleStorages addObject:title];
            }
            LWTextStorage *lastTitleStorage = titleStorages[titleArray.count-1];
            NSString *language = [NSString stringWithFormat:@"%@ - %@",model.sourceLangValue, model.targetLangValue];
            NSString *wordCount = [NSString stringWithFormat:@"%.0f字",model.wordCount];
            NSArray *contentArray;
            NSString *tasktype;
            if ([model.tasktype isEqualToString:@"1"]) {
                tasktype = @"翻译";
            }else if ([model.tasktype isEqualToString:@"2"]) {
                tasktype = @"编辑";
            }else if ([model.tasktype isEqualToString:@"3"]) {
                tasktype = @"校对";
            }else if (model.taskType) {
                tasktype = model.taskType;
            }else{
                tasktype = @"";
            }
            if (model.sourceLangValue == nil) {
                language = [NSString stringWithFormat:@"%@ - %@",model.sourcelangname, model.targetlangname];
                wordCount = [NSString stringWithFormat:@"%.0f字",model.wordcount];
                contentArray = @[language,wordCount,tasktype,model.label_idname_list];
                if (CurrentUserType == 4 || CurrentUserType == 5) {
                    NSString *price = [NSString stringWithFormat:@"%@元/千字",model.price];
                    contentArray = @[language,wordCount,price,tasktype,model.label_idname_list];
                }
            }else{
                contentArray = @[language,wordCount,tasktype,model.labels];
                if (CurrentUserType == 4 || CurrentUserType == 5) {
                    NSString *price = [NSString stringWithFormat:@"%@元/千字",model.price];
                    contentArray = @[language,wordCount,price,tasktype,model.labels];
                }
            }
            for (NSInteger j = 0; j < titleArray.count; ++ j) {
                LWTextStorage *content = [[LWTextStorage alloc] init];
                content.text = contentArray[j];
                content.frame = CGRectMake(lastTitleStorage.right + 9.0, taskContentTitle.bottom+9.0+j*24, Screen_Width-lastTitleStorage.right-9.0-18.0-60, 24);
                content.textColor = [UIColor colorWithHexString:@"#666666"];
                content.font = [UIFont systemFontOfSize:13];
                content.maxNumberOfLines = 1;
                [self addStorage:content];
            }
            
            LWTextStorage *checkAllContent = [[LWTextStorage alloc] init];
            checkAllContent.text = @"查看全文";
            checkAllContent.frame = CGRectMake(Screen_Width-78, taskContentTitle.bottom+91.0, 60, 24);
            checkAllContent.textColor = [UIColor colorWithHexString:@"#e85553"];
            checkAllContent.font = [UIFont systemFontOfSize:13];
            [checkAllContent lw_addLinkWithData:@"open"
                                          range:NSMakeRange(0, 4)
                                      linkColor:[UIColor colorWithHexString:@"#e85553"]
                                 highLightColor:nil];
            [self addStorage:checkAllContent];
            
        }else{
            LWTextStorage *taskDescription = [[LWTextStorage alloc] init];
            taskDescription.text = @"任务描述";
            taskDescription.frame = CGRectMake(18, 18, Screen_Width, 13);
            taskDescription.textColor = [UIColor colorWithHexString:@"#999999"];
            taskDescription.font = [UIFont systemFontOfSize:13];
            [self addStorage:taskDescription];
            
            LWTextStorage *taskDesContent = [[LWTextStorage alloc] init];
            if ([model.memo isEqualToString:@""] || model.memo == nil) {
                taskDesContent.text = @"暂无描述";
            }else{
                taskDesContent.text = model.memo;
            }
            taskDesContent.frame = CGRectMake(taskDescription.left, taskDescription.bottom+9.0, Screen_Width-36, CGFLOAT_MAX);
            taskDesContent.textColor = [UIColor colorWithHexString:@"#666666"];
            taskDesContent.font = [UIFont systemFontOfSize:14];
            [self addStorage:taskDesContent];
        }
        self.cellHeight = [self suggestHeightWithBottomMargin:12];
    }
    return self;
}

@end
